const redis = require("redis");
const util = require("util");

module.exports = function ({
  host,
  port = 6379,
  password,
  db = 1,
  prefix = "",
}) {
  if (!host) {
    throw new Error("redis host 未配置");
  }
  if (!password) {
    throw new Error("redis password 未配置");
  }
  const client = redis.createClient(port, host, {
    password,
    db,
    prefix,
  });
  console.log(`redis connected!!!`);
  client.getSync = util.promisify(client.get);
  return client;
};
